package com.jianguozh.difs.framework.config.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.jianguozh.difs.framework.utils.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDateTime;

/**
 * 元数据填充配置
 *
 * @author hanrs
 * @email 4076130@qq.com
 * @since 2022/3/15 11:28
 */
public class DifsMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        System.out.println(LocalDateTime.now());
        this.strictInsertFill(metaObject, "createAt", String.class, SecurityUtils.getUsername());
        this.strictInsertFill(metaObject, "createDate", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "modifyAt", String.class, SecurityUtils.getUsername());
        this.strictInsertFill(metaObject, "modifyDate", LocalDateTime.class, LocalDateTime.now());

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "modifyAt", String.class, SecurityUtils.getUsername());
        this.strictUpdateFill(metaObject, "modifyDate", LocalDateTime.class, LocalDateTime.now());
    }

}
